//合并两个有序链表
class Solution {
public:
    ListNode* mergeTwoLists(ListNode* list1, ListNode* list2)
    {
        ListNode*head=new ListNode(0);
        ListNode* cur=head;
        while(list1 && list2)
        {
            if(list1->val < list2->val)
            {
                cur->next=list1;
                list1=list1->next;
            }
            else
            {
                cur->next=list2;
                list2=list2->next;
            }
            cur=cur->next;
        }
        cur->next=list1!=nullptr?list1:list2;
        return head->next;
        
    }
};

//合并k个升序链表
class Solution {
public:
    struct cmp
    {
        bool operator()(ListNode*lA,ListNode* lB)
        {
            return lA->val > lB->val;
        }
    };
    ListNode* mergeKLists(vector<ListNode*>& lists) 
    {
        if(lists.size()==0) return nullptr;
        ListNode* head=new ListNode(-1);
        ListNode* cur=head;
        priority_queue<ListNode*,vector<ListNode*>,cmp>q;
        for(auto& node:lists)
        {
            if(node!=nullptr)
            {
                q.push(node);
            }
        }
        while(!q.empty())
        {
            cur->next=q.top();
            if(q.top()->next)
            {
                q.push(q.top()->next);
            }
            q.pop();
            cur=cur->next;
        }
        return head->next;
    }
};


//排序链表
class Solution {
public:
    ListNode* sortList(ListNode* head) 
    {
        //思路：使用归并排序。
        if(head==nullptr || head->next==nullptr) return head;
        //将链表一分为二 使用快慢指针
        ListNode* fast=head,* slow=head;
        while(fast->next!=nullptr && fast->next->next!=nullptr)
        {
            slow=slow->next;
            fast=fast->next->next;
        }
        ListNode* mid=slow->next;
        slow->next=nullptr;

        ListNode* left=sortList(head);
        ListNode* right=sortList(mid);
        ListNode* ph=new ListNode(0);
        ListNode* cur=ph;
        while(left!=nullptr && right!=nullptr)
        {
            if(left->val < right->val)
            {
                cur->next=left;
                left=left->next;
                cur=cur->next;
            }
            else
            {
                cur->next=right;
                right=right->next;
                cur=cur->next;
            }
        }
        cur->next=left!=nullptr?left:right;
        return ph->next;
    }
};

//红与黑
#include <iostream>
#include <vector>
using namespace std;
static int arr[4][2] ={{1,0},{-1,0},{0,1},{0,-1}};
void BFS(vector<vector<char>>& map,vector<vector<bool>>&Used,int sx,int sy,int& count)
{
    Used[sx][sy]=true;
    count++;
    for(int i=0;i<4;i++)
    {
        int newx=sx+arr[i][0];
        int newy=sy+arr[i][1];
        if(newx>=map.size() || newx<0 || newy>=map[0].size() || newy<0) continue;
        if(map[newx][newy]=='.' && Used[newx][newy]==false)
        {
            BFS(map,Used,newx,newy,count);
        }
    }
}
int main()
{
    int m,n;
  
    while(cin>>m)
    {
        cin>>n;
    vector<vector<char>> map(m,vector<char>(n));
    int startx=0,starty=0;
    for(int i=0;i<m;i++)
    {
        for(int j=0;j<n;j++)
        {
            cin>>map[i][j];
            if(map[i][j]=='@')
            {
                startx=i;
                starty=j;
            }
        }
    }
    int count=0;
    vector<vector<bool>>Used(m,vector<bool>(n,false));
    BFS(map,Used,startx,starty,count);
    cout<<count<<endl;
    }
    return 0;
}